#include "choose.h"
#include "ui_choose.h"
//画地图//0气,1泥土,2草，3冰，4砖，5铁
choose::choose(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::choose)
{
    ui->setupUi(this);
}

choose::~choose()
{
    delete ui;
}
void choose:: paintEvent(QPaintEvent*event)
{QPainter painter(this);
    QPixmap HQ(":/:/new/wall/image/item/HQ.png");
    painter.drawPixmap(240,480,40,40,HQ);
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<26;j++)
        {
            if(maps::mmap[i][j]==1)
            {QPixmap temp(":/:/new/wall/image/ground/dirt.png");
               painter.drawPixmap(j*20,i*20,20,20,temp );
            }
            if(maps::mmap[i][j]==2)
            {QPixmap temp(":/:/new/wall/image/ground/grass.png");
                painter.drawPixmap(j*20,i*20,20,20,temp );
        }
            if(maps::mmap[i][j]==3)
            {
                QPixmap temp(":/:/new/wall/image/ground/ice.png");
                               painter.drawPixmap(j*20,i*20,20,20,temp );
            }
            if(maps::mmap[i][j]==4)
            {
                QPixmap temp(":/:/new/wall/image/wall/brick.png");
                               painter.drawPixmap(j*20,i*20,20,20,temp );
            }
            if(maps::mmap[i][j]==5)
            {
                QPixmap temp(":/:/new/wall/image/wall/iron.png");
                               painter.drawPixmap(j*20,i*20,20,20,temp );
            }
        }
    }
    painter.setPen(Qt::blue);//设置画笔颜色
        for(int i=0;i<=26;i++){
            painter.drawLine(0,i*20,520,i*20);//画横线，270是根据坐标换算出来的
            painter.drawLine(i*20,0,i*20,520);//画竖线
        }
}
void choose:: mousePressEvent(QMouseEvent * e)
{
    int xx=e->x();int yy=e->y();
    if(xx>=520||yy>=520)
    {return;}
   maps::mmap[yy/20][xx/20]=brick;update();
}

void choose::on_pushButton_clicked()
{
    brick=0;
}

void choose::on_pushButton_3_clicked()
{
    brick=1;
}

void choose::on_pushButton_2_clicked()
{
    brick=2;
}

void choose::on_pushButton_4_clicked()
{
    brick=3;
}

void choose::on_pushButton_5_clicked()
{
    brick=4;
}

void choose::on_pushButton_6_clicked()
{
    brick=5;
}

void choose::on_pushButton_7_clicked()
{
    emit start();this->close();
}
